package ch.drshit.controller;

import javax.swing.JMenu;
import javax.swing.JMenuBar;

import ch.drshit.controller.listener.ImageMoveResizeController;
import ch.drshit.controller.listener.MenuController;
import ch.drshit.model.Model;
import ch.drshit.model.picture.Project;
import ch.drshit.view.View;

public class Controller {
	
	private Model model;
	private View view;
	private Project project = null;
	
	public Controller(Model m, View v){
		this.model = m;
		this.view = v;
	}
	
	public void controll(){
		//menu
		MenuController menucontroller = new MenuController(this);
		JMenuBar jmenubar = this.view.getFrame().getJMenuBar();
		for(int i=0;i<jmenubar.getMenuCount();i++){
			JMenu jmenu = jmenubar.getMenu(i);
			jmenu.addMenuListener(menucontroller);
			for(int r=0;r<jmenu.getItemCount();r++){
				jmenu.getItem(r).addActionListener(menucontroller);
			}
		}
		//image
		ImageMoveResizeController imrc = new ImageMoveResizeController(this);
		this.view.getFrame().addMouseWheelListener(imrc);
		this.view.getFrame().addKeyListener(imrc);
		this.view.getFrame().getJscrollhorizontal().addAdjustmentListener(imrc);
		this.view.getFrame().getJscrollvertical().addAdjustmentListener(imrc);
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	public View getView(){
		return this.view;
	}
}
